//
//  CZChangePWDViewController.m
//  nsj_iOS
//
//  Created by apple on 2017/1/11.
//  Copyright © 2017年 GCZ. All rights reserved.
//

#import "CZChangePWDViewController.h"
#import "CZVerificationBtn.h"
@interface CZChangePWDViewController ()
@property (weak, nonatomic) IBOutlet UITextField *verCodeTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordAgainTextField;
@property (nonatomic, strong) YYTimer *timer;
@property (weak, nonatomic) IBOutlet CZVerificationBtn *verificationBtn;

@end

@implementation CZChangePWDViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置密码";
    self.verificationBtn.delgate = self;
    self.verificationBtn.phoneNumber = [[NSUserDefaults standardUserDefaults] objectForKey:User_Phone];
    
    // Do any additional setup after loading the view from its nib.
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.alpha = 1;
    
    [(UIView*)[self.navigationController.navigationBar.subviews objectAtIndex:0] setAlpha:1.f];
}

- (IBAction)comfirmChange:(UIButton *)sender {
    NSString *urlString = [NSString stringWithFormat:@"%@/api/web/index.php/v1/user/update-pwd",APP_HOST];
    if (_verCodeTextField.text.length < 2) {
        [SVProgressHUD showErrorWithStatus:@"请输入正确的验证码"];
        return;
    }
    if (_passwordTextField.text.length < 6 || _passwordTextField.text.length > 12) {
        [SVProgressHUD showErrorWithStatus:@"请输入6位以上12位以下的密码"];
        return;
    }
    if (![_passwordTextField.text isEqualToString:_passwordAgainTextField.text]) {
        [SVProgressHUD showErrorWithStatus:@"两次输入密码不同"];
        return;
    }
    [GCZAFNetWorking POST:urlString params:@{@"token" : [[NSUserDefaults standardUserDefaults] objectForKey:User_Token], @"pwd" : _passwordAgainTextField.text, @"code" : _verCodeTextField.text} success:^(NSDictionary *response) {
//        DLog(@"%@", response);
        if ([response[@"code"] isEqualToString:@"200"]) {
            [SVProgressHUD showSuccessWithStatus:@"修改密码成功"];
        }
    } failure:^(NSURLSessionDataTask *operation, NSError *error) {
    }];
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
